package com.caishi.lkx.exam.model;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.caishi.lkx.common.model.Seo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zzw.common.entity.impl.BaseEntity;
import com.zzw.common.service.model.NameModel;
import com.zzw.common.service.model.base.SortModel;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.util.List;

@Schema(title = "考试")
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "ex_exam")
public class ExamModel extends BaseEntity<ExamModel> implements NameModel<ExamModel, String>, SortModel<ExamModel>, CstkModel, Seo {

    public static final String GJTK = "gjtk";
    public static final String GJTK_NAME = "高教题库";
    public static final String ZY = "zhiye";

    private String name;

    /**
     * 后台显示名称
     */
    private String serverName;

    /**
     * 行业id
     * 值为"gjtk"时表示考试为高教题库
     */
    private String industryId;

    private Integer sort;

    /**
     * 图标
     */
    @Schema(title = "图标")
    private String icon;

    /**
     * 属性
     * 0x01 热门考试
     * 0x02 推荐考试
     * 0x04 最新考试
     */
    private Integer attribute;

    @JsonIgnore
    private String cstkId;

    @TableField(exist = false)
    private String industryName;
    @TableField(exist = false)
    private Integer categoryCount;
    @TableField(exist = false)
    private List<CategoryModel> categorys;

    @Schema(title = "是否是热门考试")
    public boolean getIsHot() {
        return attribute != null && (attribute & 1) == 1;
    }

    @Schema(title = "是否是推荐考试")
    public boolean getIsRecommend() {
        return attribute != null && (attribute & 2) == 2;
    }

    @Schema(title = "是否最新")
    public boolean getIsNew() {
        return attribute != null && (attribute & 4) == 4;
    }

    @Override
    public String getCode() {
        return getId();
    }

    @Override
    public String getKeyword() {
        return getName();
    }


    /**
     * 认证标志
     * 0000 0000  ---- --机构认证 用户认证
     */
    @TableField(exist = false)
    private byte authFlag;

    public String getServerName() {
        return StrUtil.isEmpty(serverName) ? name : serverName;
    }
}
